import React,{useEffect} from 'react'
import { Form, Icon, Input, Button, Checkbox } from 'antd';
import Head from './Head'
import './head.css'
import {check} from './actionCreators'
import {connect } from 'react-redux'
import {func} from './actionCreators'
import ModalDemo from './ModalDemo';
const Check = (props) => {
    let i=0;
    useEffect(() => {
        props.dispatch(check());

    },[])
    
   
    return (
        <div>
            <Head/>
            <div className='title'>
                审批管理>未审批
            </div>
            <div className='checktable'>
            <table border='1' cellspacing='0'>
                    <tr>
                        <th>排序</th>
                        <th>学号</th>
                        <th>姓名</th>
                        
                        <th>预约教室</th>
                        <th>预约日期</th>
                        <th>预约时间</th>
                        <th>类型</th>
                        <th>申请原因</th>
                        <th>操作</th>               
                    </tr>
                    {props.checks.map((item)=>{
                        item.Start=item.Start+''
                        item.Endtime=item.Endtime+''
                        i++;
                        return<tr>
                            <td>{i}</td>
                            <td>{item.Sno} </td>
                            <td>{item.Sname}</td>
                            <td>{item.Cno} </td>
                            <td>{item.time}</td>
                            <td >{item.Start.slice(0,item.Start.length-2)+':'+ item.Start.slice(-2)}-{item.Endtime.slice(0,item.Endtime.length-2)+':'+ item.Endtime.slice(-2)}</td>
                            <td>{item.Type} </td>
                            <td>{item.Text}</td>
                            <td>
                            <button
                                onClick={(check)=>{
                                    let Submittime=item.Submittime;
                                    check={type:'ok',table:'Approval',Submittime:Submittime,cno:item.Cno,start:item.Start,end:item.Endtime,time:item.time,types:item.Type,text:item.Text,sno:item.Sno,Aname:item.Aname}
                                    props.dispatch(func(check))
                                    setTimeout(()=>{
                                        alert('通过审批');
                                        props.history.go(0);
                                    },1000)
                                }}
                                >通过</button>
                                <button
                                onClick={(check)=>{
                                    let reason = prompt("reason","填写拒绝原因")
                                    console.log(reason)
                                    let Submittime=item.Submittime;
                                    check={type:'no',table:'Approval',Submittime:Submittime,cno:item.Cno,start:item.Start,end:item.Endtime,time:item.time,types:item.Type,text:item.Text,reason:reason,sno:item.Sno}
                                    props.dispatch(func(check))
                                    setTimeout(()=>{
                                        alert('拒绝申请');
                                        props.history.go(0);                                       
                                       
                                    },1000)
                                    // console.log(check)
                                    
                                }}
                                >拒绝</button>

                            </td>                                   
                        </tr>
                    })} 
                </table>

            </div>
            {/* <ModalDemo /> */}
            
        </div>
    )
}
const mapStateToProps=(state)=>({
    checks:state.check.checks,
    rets:state.func.rets

    
  })
export default connect(mapStateToProps)(Check)
